<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


class Account extends CI_Controller {
	
	function __construct(){
		parent::__construct();
	}
	
	//交易记录 
	function account_list(){
		//$user = $this->session->userdata('ych_user');
		$headers = apache_request_headers();
		$user_id = isset($headers['user_id'])? intval($headers['user_id']) : 0;
		$token = isset($headers['token'])? $headers['token'] : '';
		$token_key = 'token_'.$user_id;
		$token_val = $this->mycache->get($token_key);
		if(!$user_id || $token!=$token_val){
			$ret['msg'] = '请先登录';
			$ret['code'] = 1;
			echo json_encode($ret);exit;
		}
		$data['code'] = 0;
		echo json_encode($data);
		//$this->load->view('/mobile/account_list', $data);
	}
	
	/**
	 * 更多提现
	 * @param int $page
	 */
	function cashed_more(){
		//$user = $this->session->userdata('ych_user');
		$headers = apache_request_headers();
		$user_id = isset($headers['user_id'])? intval($headers['user_id']) : 0;
		$token = isset($headers['token'])? $headers['token'] : '';
		$token_key = 'token_'.$user_id;
		$token_val = $this->mycache->get($token_key);
		if(!$user_id || $token!=$token_val){
			$ret['msg'] = '请先登录';
			$ret['code'] = 1;
			echo json_encode($ret);exit;
		}
		$data = array();
		$page =  intval($this->input->get_post('page'));
		$page = $page ? $page : 1;//默认第一页
		$parms['page_size'] = 8;
		$parms['page_start'] = ($page-1)*$parms['page_size'];
		$parms['where']['user_id'] = $user_id;
		//充值统计
		$this->load->model('Accountcash_model', 'cash');
		$resData = $this->cash->get_accountcash_list($parms);
		$cash_list = $resData['accountcash_list'];
		$cash_status 	= $this->cash->arrays("account_cash_status");
		$cash_lsit1 = array();
		foreach($cash_list as $cash){
			$tmp = array();
			$tmp['total'] 	= number_format($cash['total'],2);//提现金额
			$tmp['fee'] 	= number_format($cash['fee'],2);//提现手续费
			$tmp['add_time'] = date('m-d H:i', $cash['add_time']);//提现时间
			$tmp['fstatus_text'] = $cash_status[$cash['fstatus']];//状态
			$cash_lsit1[] = $tmp;
		}
		echo json_encode($cash_lsit1);
	}
	
	
	/**
	 * 更多充值
	 * @param int $page
	 */
	function recharge_log_more(){
		//$user = $this->session->userdata('ych_user');
		$headers = apache_request_headers();
		$user_id = isset($headers['user_id'])? intval($headers['user_id']) : 0;
		$token = isset($headers['token'])? $headers['token'] : '';
		$token_key = 'token_'.$user_id;
		$token_val = $this->mycache->get($token_key);
		if(!$user_id || $token!=$token_val){
			$ret['msg'] = '请先登录';
			$ret['code'] = 1;
			echo json_encode($ret);exit;
		}
		$data = array();
		$page =  intval($this->input->get_post('page'));
		$page = $page ? $page : 1;//默认第一页
		$parms['page_size'] = 8;
		$parms['page_start'] = ($page-1)*$parms['page_size'];
		$parms['where']['user_id'] = $user_id;
		$this->load->model('Accountrecharge_model', 'recharge');
		$this->load->model('Payment_model', 'payment');
		//充值统计
		$resData = $this->recharge->get_accountrecharge_list($parms);
		$data['recharge_list'] 	= $resData['accountrecharge_list'];
		$recharge_status 		= $this->recharge->arrays("account_recharge_status");
		$recharge_type 			= $this->recharge->arrays("account_recharge_type");
		$payment_list 			= $this->payment->get_list();
		$recharge_list = array();
		foreach ($data['recharge_list'] as $recharge){
			$tmp = array();
			$tmp['payment'] 		= isset($payment_list[$recharge['payment']]) ? $payment_list[$recharge['payment']]['name'] : '线下充值';//充值方式
			$tmp['money'] 			= number_format($recharge['money'],2);//充值金额
			$tmp['fstatus_text'] 	= $recharge_status[$recharge['fstatus']];//状态
			$tmp['add_time'] 		= date('m-d H:i', $recharge['add_time']);//充值时间
			$recharge_list[] = $tmp;
		}
		echo json_encode($recharge_list);
	}
	
	/**
	 * 更多资金记录
	 * @param int $page
	 */
	function account_log_more(){
		//$user = $this->session->userdata('ych_user');
		$headers = apache_request_headers();
		$user_id = isset($headers['user_id'])? intval($headers['user_id']) : 0;
		$token = isset($headers['token'])? $headers['token'] : '';
		$token_key = 'token_'.$user_id;
		$token_val = $this->mycache->get($token_key);
		if(!$user_id || $token!=$token_val){
			$ret['msg'] = '请先登录';
			$ret['code'] = 1;
			echo json_encode($ret);exit;
		}
		$page =  intval($this->input->get_post('page'));
		$page = $page ? $page : 1;//默认第一页
		$parms['page_size'] = 8;
		$parms['page_start'] = ($page-1)*$parms['page_size'];
		$parms['where']['user_id'] = $user_id;
		$this->load->model('Accountlog_model', 'accountlog');
		$resData = $this->accountlog->get_accountlog_list($parms);
		$account_log_list = $resData['accountlog_list'];
		$log_type 			= $this->accountlog->arrays("account_type");
		$account_log_list1 = array();
		foreach($account_log_list as $account_log){
			$tmp = array();
			$tmp['ftype'] 		= $log_type[$account_log['ftype']];//资金操作类型
			$tmp['money'] 		= number_format($account_log['money'],2);//操作资金
			$tmp['add_time'] 	= date('m-d H:i', $account_log['add_time']);//操作时间
			$account_log_list1[] = $tmp;
		}
		echo json_encode($account_log_list1);
	}
	
}